//
//  MIneController.m
//  JF_New_DYKT
//
//  Created by 陈雷 on 2017/8/22.
//  Copyright © 2017年 陈雷. All rights reserved.
//

#import "MIneController.h"
#import "JFMineCell.h"
#import "SettingController.h"
#import "FirstStamentOfIncomeAndExpandingController.h"
#import "PersonInformationController.h"
#import "MineMessageModel.h"
#import "OrderMarketController.h"

@interface MIneController ()<UITableViewDelegate,UITableViewDataSource>

{
    MineMessageModel *model;
}

@property (nonatomic,strong) UITableView *tbv;

@property (strong, nonatomic) IBOutlet UIView *mineHeaderV;

@property (nonatomic,strong) NSArray *lefImvArr;
@property (nonatomic,strong) NSArray *leftTitleArr;

@property (weak, nonatomic) IBOutlet UIImageView *userLogo;

@property (weak, nonatomic) IBOutlet UILabel *userNameL;

@property (weak, nonatomic) IBOutlet UILabel *userIdL;

@property (weak, nonatomic) IBOutlet UILabel *totoalMoneyL;

@property (weak, nonatomic) IBOutlet UILabel *shouyiL;


@end

@implementation MIneController

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.lefImvArr = @[@[@"JFGG学院",@"JFGG添加订阅",@"JFGG足迹",@"JFGG收藏"],@[@"JFGG麦克风",@"JFGG任务"],@[@"JFGG报纸",@"JFGG地址",@"JFGG设置"]];
    self.leftTitleArr = @[@[@"学院",@"订阅",@"足迹",@"收藏"],@[@"申请主播",@"任务中心"],@[@"我的校报",@"收货地址",@"设置"]];
    
    [self baseConfig];
    
}

- (void)baseConfig{
    
    self.tbv = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KSCreenWidth, KSCreenHeight - 46) style:UITableViewStyleGrouped];
    self.tbv.delegate = self;
    self.tbv.dataSource = self;
    [self.view addSubview:self.tbv];
    
    [self.tbv registerNib:[UINib nibWithNibName:@"JFMineCell" bundle:nil] forCellReuseIdentifier:@"JFMineCell"];
    self.tbv.separatorInset = UIEdgeInsetsZero;
    
    self.mineHeaderV.frame = CGRectMake(0, 0, KSCreenWidth, 263);
    
    self.tbv.tableHeaderView = self.mineHeaderV;
    
    self.tbv.separatorInset = UIEdgeInsetsMake(0, 10, 0, 10);
    
    self.tbv.separatorColor = [UIColor clearColor];
    
    
    self.tbv.tableFooterView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KSCreenWidth, 20)];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return .001;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    NSArray *arr = self.lefImvArr[section];
    return arr.count;
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return self.lefImvArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    JFMineCell *mineCell = [tableView dequeueReusableCellWithIdentifier:@"JFMineCell" forIndexPath:indexPath];
    mineCell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    if (indexPath.row == 0) {
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:mineCell.backV.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(5, 5)];
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.frame = mineCell.bounds;
        maskLayer.path = maskPath.CGPath;
        mineCell.backV.layer.mask = maskLayer;
    }else if (indexPath.row == [self tableView:self.tbv numberOfRowsInSection:indexPath.section] - 1){
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:mineCell.backV.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(5, 5)];
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.frame = mineCell.bounds;
        maskLayer.path = maskPath.CGPath;
        mineCell.backV.layer.mask = maskLayer;
    }else{
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:mineCell.backV.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(0, 0)];
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.frame = mineCell.bounds;
        maskLayer.path = maskPath.CGPath;
        mineCell.backV.layer.mask = maskLayer;
    }
    
    mineCell.leftImv.image = [UIImage imageNamed:self.lefImvArr[indexPath.section][indexPath.row]];
    mineCell.leftTitle.text = self.leftTitleArr[indexPath.section][indexPath.row];
    
    return mineCell;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    //学院
    
    if (indexPath.section == 0 && indexPath.row == 0) {
        OrderMarketController *orderVc = [[OrderMarketController alloc]init];
        
        [orderVc setHidesBottomBarWhenPushed:YES];
        
        [self.navigationController pushViewController:orderVc animated:YES];
    }
    
    //设置
    if (indexPath.section == 2 && indexPath.row == 2) {
        
        SettingController *settingVc = [[SettingController alloc]init];
        
        [self.navigationController pushViewController:settingVc animated:YES];
        
    }
    
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UIView *sectionV = [UIView new];
    sectionV.backgroundColor = [UIColor colorWithHexString:@"eeeeee"];
    return sectionV;
    
}


- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
    [self getAllUserinfo];
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.hidden = NO;
    
}


- (IBAction)moneyAction:(UIButton *)sender {
    
    if (sender.tag == 100) {
        
    }else if (sender.tag == 101){
        FirstStamentOfIncomeAndExpandingController *vc = [[FirstStamentOfIncomeAndExpandingController alloc]init];
        [vc setHidesBottomBarWhenPushed:YES];
        [self.navigationController pushViewController:vc animated:YES];
    }
    
}


- (IBAction)changePersonInformationVc:(UIButton *)sender {
    PersonInformationController *personVc = [[PersonInformationController alloc]init];
    
    personVc.msgModel = model;
    
    [personVc setHidesBottomBarWhenPushed:YES];
    [self.navigationController pushViewController:personVc animated:YES];
}


- (void)getAllUserinfo{

    NSString *urlStr = [NSString stringWithFormat:@"%@user/Personal/getUserInfo",kDomainName];
    
    NSDictionary *paraDic = @{@"userId":USERID};
    
    BaseRequest *request =  [BaseRequest sharedBaseRequest];
    [request post:urlStr params:paraDic success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if ([responseObject[@"code"] isEqualToString:@"1"] ) {

            model = [MineMessageModel mj_objectWithKeyValues:responseObject[@"data"]];
            [self.userLogo sd_setImageWithURL:[NSURL URLWithString:model.LOGO] placeholderImage:[UIImage imageNamed:@"headerImgZhanWei.png"]];
            self.userNameL.text = model.NICK_NAME;
            
            self.userIdL.text = [NSString stringWithFormat:@"ID:%@",model.ID];
            
        }else{
            [JKToast showWithText:responseObject[@"message"]];
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
    }];

}


@end
